package Utils;

public class ArrayUtils {
    //随机生成长度为amount，元素最大为max的数组
    public static int[] generateArray(int amount, int max) {
        int[] arr = new int[amount];
        for (int i = 0; i < amount; i++) {
            arr[i] = (int) (Math.random() * (max + 1)) - (max >> 1);
        }
        return arr;
    }

    public static int[] generatePositiveArray(int amount, int max) {
        int[] arr = new int[amount];
        for (int i = 0; i < amount; i++) {
            arr[i] = (int) (Math.random() * (max + 1));
        }
        return arr;
    }

    //交换数组元素
    public static void swap(int[] arr, int i1, int i2) {
        int temp = arr[i1];
        arr[i1] = arr[i2];
        arr[i2] = temp;
    }

    public static boolean judge(int[] right, int[] test) {
        if (right.length != test.length) return false;
        for (int i = 0; i < right.length; i++) {
            if (right[i] != test[i]) {
                System.out.println("Oops! Diff occurs at " + i);
                return false;
            }
        }
        return true;
    }
}
